<template>
  <div class="shop">
   <el-form ref="filtrateForm" :inline="true" size="mini" :model="form" class="form">
      <el-form-item label="操作类型:">
        <el-select v-model="form.type" placeholder="请选择">
          <!-- <el-option label="全部" value='0'></el-option> -->
          <el-option
            v-for="(item, index) in typeList"
            :key="index"
            :label="item.text"
            :value="item.type"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="充值时间:">
        <el-row>
          <el-col :span="18">
            <el-date-picker
              v-model="pickerTime"
              type="daterange"
              align="right"
              unlink-panels
              format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              :default-time="['00:00:00', '23:59:59']"
              :picker-options="timeOptions"
            ></el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-button size="mini" type="primary" @click="searchLogData">搜索</el-button>
   </el-form>
   <el-table
      :data="tableData"
      max-height="650"
      :cell-style="tc"
      :header-cell-style="tccolor"
      v-loading="listLoading"
    >
      <el-table-column fixed prop="created_at" label="操作时间"></el-table-column>
      <el-table-column prop="operator" label="登录账号"></el-table-column>
      <el-table-column prop="type_text" label="操作类型"></el-table-column>
      <!-- <el-table-column prop="charge_time" label="操作详细"></el-table-column> -->
      <el-table-column prop="remark" label="备注" ></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="pageChange"
        :current-page="form.pageNum"
        :page-sizes="[20, 50, 100]"
        :page-size="form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
// import { parseTime } from "@/utils/common";
import {adminLogList,
  adminLogListAll,
  adminLogDelete
} from '@/api/store'
// import {shopAdminLogType,shopAdminLog} from '@/api/shopdetail'
export default {
  data () {
    return {
      form: {
        type: '',
        startTime: '',
        endTime: '',
        pageNum: 1,
        pageSize: 20
      },
      total: 100,
      listLoading: false,
      tableData: [],
      typeList:[{
        text: '无',
        type:0
      },{
        text: '新增入驻小店',
        type:1
      },{
        text: '小店基本信息修改',
        type:2
      },{
        text: '升级押金入驻小店',
        type:3
      },{
        text: '证件信息修改',
        type:4
      },{
        text: '退费移除撤回',
        type:5
      },{
        text: '入驻审核通过',
        type:6
      },{
        text: '入驻审核驳回',
        type:7
      },{
        text: '退费移除小店',
        type:8
      },{
        text: '强制移除小店',
        type:9
      },{
        text: '移除小店会员',
        type:10
      },{
        text: '数据导出',
        type:11
      }],
      timeOptions: {
        shortcuts: [
          {
            text: "最近一天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", [start, end]);
            }
          },

          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近15天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      },
      pickerTime: "",
    }
  },
  mounted () {
    // this.getshopAdminLogTypeData()
    this.getList()
  },
  methods: {

   searchLogData(){
   this.getList()
   },
       // 导出
   out() {
      const form = this.form;
      if (this.pickerTime !== "" && this.pickerTime !== null) {
        form.startTime = this.parseTime(this.pickerTime[0]);
        form.endTime = this.parseTime(this.pickerTime[1]);
      } else {
        form.startTime = ''
        form.endTime = ''
      }
    },
    pageChange(page) {
      this.form.pageNum = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.pageChange(1);
    },

    tc() {
      return "text-align:center; color:#333333; font-size:12px;";
    },
    tccolor() {
      return "text-align:center;background-color:#f5f5f5; font-size:14px;";
    },
    async getshopAdminLogTypeData(){
      let  res = await shopAdminLogType()
      if(res.code === 200){
         this.typeList = res.data
      }
    },
    async getList () {
      const form = this.form;
      console.log(this.pickerTime);
      if (this.pickerTime !== "" && this.pickerTime !== null) {
        form.startTime = this.parseTime(this.pickerTime[0]);
        form.endTime = this.parseTime(this.pickerTime[1]);
      }  else {
        form.startTime = ''
        form.endTime = ''
      }
      if(this.form.type == 0){
        this.form.type = ''
      }
      this.listLoading = true;
      console.log("日期",form.endTime,form.startTime)
      let url;
                url = 'pageNum='+this.form.pageNum+
                    '&pageSize='+this.form.pageSize
                this.form.type?url +="&type=" + this.form.type:''
                this.form.startTime?url +="&startTime=" + this.form.startTime:''
                this.form.endTime?url +="&endTime=" + this.form.endTime:''
      let res = await adminLogList(url)
      if(res.code === 200){
        this.tableData = res.data.list
        this.total = res.data.total
        this.listLoading = false

      }else{
        this.listLoading = false
        this.$message.error(res.message)
      }
    },

  }
}
</script>

<style lang="scss" scoped>
.shop {
  padding: 20px;
  .form{
    float: right;
  }
  .pagination{
    float: right;
    margin-top: 30px;
  }
}
</style>
